package com.huaxiafinance.management.service.impl;

import com.huaxiafinance.management.mapper.PermissionMapper;
import com.huaxiafinance.management.model.Permission;
import com.huaxiafinance.management.service.PermissionService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service("permissionService")
public class PermissionServiceImpl implements PermissionService {

	private static final Logger log = Logger.getLogger(PermissionServiceImpl.class);

	@Autowired
	private PermissionMapper permissionMapper;

	@Override
	public List<Permission> queryPermission() throws Exception {

		try {
			return permissionMapper.queryPermission();
		} catch (Exception e) {
			log.error(e.getMessage(), e);
		}

		return Collections.emptyList();
	}

	@Override
	public boolean addPermission(Permission permission) throws Exception {
		int i = 0;

		try {
			i = permissionMapper.insert(permission);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
		}
		return i > 0;
	}

	@Override
	public boolean updatePermission(Permission permission) throws Exception {
		int i = 0;

		try {
			i = permissionMapper.update(permission);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
		}
		return i > 0;
	}

	@Override
	public boolean deletePermission(Integer id) throws Exception {
		int i = 0;

		try {
			i = permissionMapper.del(id);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
		}
		return i > 0;
	}
}